package com.yue.jpa.domain.repositories;

import com.querydsl.core.types.Predicate;
import com.yue.jpa.UserDto;
import com.yue.jpa.domain.entity.QUser;
import com.yue.jpa.domain.entity.User;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

/**
 * Created by qiuyang on 2017/6/12.
 *
 * find/get/query By***
 * count By ***
 * delete/remove By ****
 *
 */
public interface UserRepository extends CrudRepository<User, Long>, QueryDslPredicateExecutor<User> {
    static final QUser Q_USER = QUser.user;

    List<User> findByLastname(String lastname);

    @Query("select new com.yue.jpa.UserDto(user.id, user.firstname) from User user")
    List<UserDto> all();

    long countByLastname(String lastname);

    long deleteByLastname(String lastname);


    /**
     * List<Person> findByEmailAddressAndLastname(EmailAddress emailAddress, String lastname);

     * // Enables the distinct flag for the query
     * List<Person> findDistinctPeopleByLastnameOrFirstname(String lastname, String firstname);
     * List<Person> findPeopleDistinctByLastnameOrFirstname(String lastname, String firstname);

     * // Enabling ignoring case for an individual property
     * List<Person> findByLastnameIgnoreCase(String lastname);
     * // Enabling ignoring case for all suitable properties
     * List<Person> findByLastnameAndFirstnameAllIgnoreCase(String lastname, String firstname);

     * // Enabling static ORDER BY for a query
     * List<Person> findByLastnameOrderByFirstnameAsc(String lastname);
     * List<Person> findByLastnameOrderByFirstnameDesc(String lastname);
     */

    /**   Limiting the result size of a query with Top and First
     * User findFirstByOrderByLastnameAsc();
     * User findTopByOrderByAgeDesc();
     * Page<User> queryFirst10ByLastname(String lastname, Pageable pageable);
     * Slice<User> findTop3ByLastname(String lastname, Pageable pageable);
     * List<User> findFirst10ByLastname(String lastname, Sort sort);
     * List<User> findTop10ByLastname(String lastname, Pageable pageable);
     */
}
